﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GmFamilyService.h"
#include "NdbDataSchema.h"
#include "NdbObjectSchematic.h"
#include "GbmpQuickCast.h"
#include "DbDataSchema.h"
#include "IExternalObject.h"

namespace gcmp
{
    class Vector3d;
}
namespace gfam
{
    /// \brief 连接点形状
    enum class FamilyConnectorShape : int32_t
    {
        Undefined = -1, ///< 未定义
        Rect = 0,      ///< 矩形
        Circle,        ///< 圆形
        Ellipse,       ///< 椭圆形
        Point,         ///< 点
        CustomShape,
    };

    class GM_FAMILY_SERVICE_EXPORT IFamilyConnectorShape : public gcmp::IDbObject
    {
        DEFINE_CAST_DERIVED(gfam::IFamilyConnectorShape, gcmp::IDbObject);
    public:
        /// \brief 获取连接件形状类型
        /// 
        /// \return 连接件形状类型
        virtual FamilyConnectorShape GetFamilyConnectorShape() const = 0;

        /// \brief 设置连接件形状类型
        /// 
        /// \param connectorShapType 连接件形状类型
        virtual bool SetFamilyConnectorShape(const FamilyConnectorShape& connectorShape) = 0;
    };



    class GM_FAMILY_SERVICE_EXPORT FamilyConnectorRectShape : public gcmp::NdbObjectSchematic, public IFamilyConnectorShape
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gfam, FamilyConnectorRectShape, gcmp::NdbObjectSchematic, D8C6A274 - 36B5 - 4E2D - BB75 - B69AA76B6A6F, gmfamilyservice, gfam::IFamilyConnectorShape)
            DATA(double, Width)
            DATA(double, Height)
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)

        DBOBJECT_DATA_END

    public:

        /// \brief 创建矩形形状
        ///
        /// \param width 矩形形状宽度
        /// \param height 矩形形状高度
        /// \return 创建成功返回矩形形状，创建失败返回nullptr
        static gcmp::OwnerPtr<FamilyConnectorRectShape> Create(double width, double height);

        /// \brief 获取连接件形状类型
        /// 
        /// \return 连接件形状类型
        virtual FamilyConnectorShape GetFamilyConnectorShape() const override;

        /// \brief 设置连接件形状类型
        /// 
        /// \param connectorShapType 连接件形状类型
        virtual bool SetFamilyConnectorShape(const FamilyConnectorShape& connectorShapType) override;


        /// \brief 获取矩形宽度
        /// 
        /// \return 矩形宽度
        double GetWidth() const { return GetWidth__(); }

        /// \brief 设置矩形宽度
        /// 
        /// \param 矩形宽度
        void SetWidth(double width);

        /// \brief 获取矩形高度
        /// 
        /// \return 矩形高度
        double GetHeight() const { return GetHeight__(); }

        /// \brief 设置矩形高度
        /// 
        /// \param 矩形高度
        void SetHeight(double height);

    public: //实现NdbObject接口
        virtual gcmp::NdbObject* GetTopOwnerObject() const override;


        bool SetOwnerElement(gcmp::IElement* pElement) { m_pOwnerElement = pElement; return true; }


    };

    class GM_FAMILY_SERVICE_EXPORT FamilyConnectorCircleShape : public gcmp::NdbObjectSchematic, public IFamilyConnectorShape
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gfam, FamilyConnectorCircleShape, gcmp::NdbObjectSchematic, 9397164F - AF10 - 460F - B7F6 - 8A880027724B, gmfamilyservice, gfam::IFamilyConnectorShape)
            DATA(double, Radius)
            DATA(Bool, IsShowRadius)
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)

        DBOBJECT_DATA_END

    public:
        /// \brief 创建圆形形状
        ///
        /// \param radius 半径
        /// \param isShowRadius 是否显示半径
        /// \return 创建成功返回圆形形状，创建失败返回nullptr
        static gcmp::OwnerPtr<FamilyConnectorCircleShape> Create(double radius, bool isShowRadius);

        /// \brief 获取连接件形状类型
        /// 
        /// \return 连接件形状类型
        virtual FamilyConnectorShape GetFamilyConnectorShape() const override;

        /// \brief 设置连接件形状类型
        /// 
        /// \param connectorShapType 连接件形状类型
        virtual bool SetFamilyConnectorShape(const FamilyConnectorShape& connectorShapeType) override;

        /// \brief 获取半径
        /// 
        /// \return 半径
        double GetRadius() const{ return GetRadius__(); }

        /// \brief 设置半径
        /// 
        /// \param 半径
        void SetRadius(double radius);

        /// \brief 是否显示半径
        /// 
        /// \return 显示半径返回true，否则返回false
        bool IsShowRadius() const { return GetIsShowRadius__(); }

        /// \brief 设置是否显示半径
        /// 
        /// \param isShowRadius 是否显示半径
        void SetShowRadius(bool isShowRadius);

    public: //实现NdbObject接口
        virtual gcmp::NdbObject* GetTopOwnerObject() const override;


        bool SetOwnerElement(gcmp::IElement* pElement) { m_pOwnerElement = pElement; return true; }


    };

    class GM_FAMILY_SERVICE_EXPORT FamilyConnectorEllipseShape : public gcmp::NdbObjectSchematic, public IFamilyConnectorShape
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gfam, FamilyConnectorEllipseShape, gcmp::NdbObjectSchematic, 3D7B8DE5 - F1C9 - 48C9 - 8F03 - 0F87072FD970, gmfamilyservice, gfam::IFamilyConnectorShape)
            DATA(double, EllipseWidth)
            DATA(double, EllipseHeight)
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)

        DBOBJECT_DATA_END

    public:
        /// \brief 创建椭圆形状
        ///
        /// \param ellipseWidth 椭圆宽度
        /// \param ellipseHeight 椭圆高度
        /// \return 创建成功返回椭圆形状，创建失败返回nullptr
        static gcmp::OwnerPtr<FamilyConnectorEllipseShape> Create(double ellipseWidth, double ellipseHeight);

        /// \brief 获取连接件形状类型
        /// 
        /// \return 连接件形状类型
        virtual FamilyConnectorShape GetFamilyConnectorShape() const override;

        /// \brief 设置连接件形状类型
        /// 
        /// \param connectorShapType 连接件形状类型
        virtual bool SetFamilyConnectorShape(const FamilyConnectorShape& connectorShapeType) override;

        /// \brief 获取椭圆宽度
        /// 
        /// \return 椭圆宽度
        double GetEllipseWidth() const { return GetEllipseWidth__(); }

        /// \brief 获取椭圆宽度
        /// 
        /// \param ellipseWidth 椭圆宽度
        void SetEllipseWidth(double ellipseWidth);

        /// \brief 获取椭圆高度
        /// 
        /// \return 椭圆高度
        double GetEllipseHeight() const { return GetEllipseHeight__(); }

        /// \brief 获取椭圆高度
        /// 
        /// \param height 椭圆高度
        void SetEllipseHeight(double height);

    public: //实现NdbObject接口
        virtual gcmp::NdbObject* GetTopOwnerObject() const override;


        bool SetOwnerElement(gcmp::IElement* pElement) { m_pOwnerElement = pElement; return true; }


    };

    class GM_FAMILY_SERVICE_EXPORT FamilyConnectorPointShape : public gcmp::NdbObjectSchematic, public IFamilyConnectorShape
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gfam, FamilyConnectorPointShape, gcmp::NdbObjectSchematic, 6945B971 - 1750 - 46E9 - 92C7 - 82CFCAFCF52F, gmfamilyservice, gfam::IFamilyConnectorShape)
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)

        DBOBJECT_DATA_END

    public:
        /// \brief 创建点式形状
        ///
        /// \return 创建成功返回点式形状，创建失败返回nullptr
        static gcmp::OwnerPtr<FamilyConnectorPointShape> Create();

        /// \brief 获取连接件形状类型
        /// 
        /// \return 连接件形状类型
        virtual FamilyConnectorShape GetFamilyConnectorShape() const override;

        /// \brief 设置连接件形状类型
        /// 
        /// \param connectorShapType 连接件形状类型
        virtual bool SetFamilyConnectorShape(const FamilyConnectorShape& connectorShapeType) override;
    public: //实现NdbObject接口
        virtual gcmp::NdbObject* GetTopOwnerObject() const override;


        bool SetOwnerElement(gcmp::IElement* pElement) { m_pOwnerElement = pElement; return true; }


    };

    class GM_FAMILY_SERVICE_EXPORT IFamilyConnectorType : public gcmp::IDbObject
    {
        DEFINE_CAST_DERIVED(IFamilyConnectorType, gcmp::IDbObject)

    public:
        /// \brief 创建连接件类型
        ///
        /// \param connectionTypeId 连接件类型Id
        /// \param connectorTypeName 连接件名称
        /// \param description 描述
        /// \return 创建成功返回连接件类型，创建失败返回nullptr
        static gcmp::OwnerPtr<IFamilyConnectorType> Create(Int32 connectionTypeId, const std::wstring& connectorTypeName, const std::wstring &description);

        /// \brief 获取连接件类型Id
        /// 
        /// \return 连接件类型Id
        virtual const Int32 GetConnectionTypeId() const = 0;

        /// \brief 设置连接件类型Id
        /// 
        /// \param connectionTypeId 连接件类型Id
        virtual void SetConnectionTypeId(Int32 connectionTypeId) = 0;

        /// \brief 获取连接件类型名称
        /// 
        /// \return 连接件类型名称
        virtual std::wstring GetConnectorTypeName() const = 0;

        /// \brief 设置连接件类型名称
        /// 
        /// \param typeName 连接件类型名称
        virtual void SetConnectorTypeName(std::wstring typeName) = 0;

        /// \brief 获取连接件类型描述信息
        /// 
        /// \return 连接件描述信息
        virtual std::wstring GetDescription() const = 0;

        /// \brief 设置连接件描述信息
        /// 
        /// \param description 连接件描述信息
        virtual void SetDescription(std::wstring description) = 0;

    };
}

